//
//  ImagesLayout.swift
//  MKPhotoDetailDemo
//
//  Created by 劢克科技 on 2019/3/22.
//  Copyright © 2019 劢克科技. All rights reserved.
//

import UIKit

class ImagesLayout: UICollectionViewFlowLayout {
    
    var padding: CGFloat = 2
    var lineNumber: CGFloat = 4
    
    override init() {
        super.init()
        
        let itemWidth = getItemWidth(padding: padding, lineNumber: lineNumber)
        itemSize = CGSize(width: itemWidth, height: itemWidth)
        minimumLineSpacing = padding
        minimumInteritemSpacing = padding
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func getItemWidth(padding: CGFloat, lineNumber: CGFloat) -> CGFloat {
        let w = (UIScreen.main.bounds.width - (lineNumber - 1) * padding) / lineNumber
        return w
    }
}
